package service

import (
	"blog_server/internal/model"
	"blog_server/pkg/app"
)

type TagCountRequest struct {
	Name string `form:"name" binding:"max=100"`
	State uint8 `form:"state, default=1" binding:"oneof= 0 1"`
}

type TagListRequest struct {
	Name string `form:"name" binding:"max=100"`
	State uint8 `form:"state,default=1" binding:"oneof= 0 1"`
}

type TagCreateRequest struct {
	Name string `form:"name" binding:"max=100"`
	State uint8 `form:"state,default=1" binding:"oneof= 0 1"`
	CreatedBy string `form:"created_by" binding:"required,min=2,max=100"`
}

type TagUpdateRequest struct {
	ID uint32 `form:"id" binding:"required,gte=1"`
	Name string `form:"name" binding:"max=100"`
	State uint8 `form:"state,default=1" binding:"oneof= 0 1"`
	ModifiedBy string `form:"modified_by" binding:"required,min=2,max=100"`
}

type TagDeleteRequest struct {
	ID uint32 `form:"id" binding:"required,gte=1"`
}

func (s *Service) CountTag(param *TagCountRequest) (int, error)  {
	return s.dao.CountTag(param.Name, param.State)
}

func (s *Service) GetTagList(param *TagListRequest, pager app.Pager) ([]model.Tag, error)  {
	return s.dao.GetTagList(param.Name, param.State, uint8(pager.Page), pager.PageSize)
}

func (s *Service) CreateTag(param *TagCreateRequest) error {
	return s.dao.CreateTag(param.Name, param.State, param.CreatedBy)
}

func (s *Service) UpdateTag(param *TagUpdateRequest) error {
	return s.dao.UpdateTag(param.ID, param.Name, param.State, param.ModifiedBy)
}

func (s *Service) DeleteTag(param *TagDeleteRequest) error {
	return s.dao.DeleteTag(param.ID)
}

